package com.learn.cloud.validator.enums;

import lombok.Getter;

/**
 * @description: 性别枚举
 * <p>https://blog.csdn.net/weixin_47952625/article/details/110874173</p>
 * @author: cong zhi
 * @createDate: 2022/2/6 12:00
 * @updateUser: cong zhi
 * @updateDate: 2022/2/6 12:00
 * @updateRemark: 修改内容
 * @version: v1.0
 */
@Getter
public enum GenderEnum {
    /**
     * 性别:男
     */
    MALE(1, "男"),
    /**
     * 性别:女
     */
    FEMALE(2, "女"),
    /**
     * 未知
     */
    UNKNOWN(3, "未知");

    private final Integer code;

    private final String name;

    GenderEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static GenderEnum codeToEnum(Integer value) {
        if (null != value) {
            for (GenderEnum genderEnum : GenderEnum.values()) {
                if (genderEnum.getCode().equals(value)) {
                    return genderEnum;
                }
            }
        }
        return null;
    }
}
